import { _decorator, Component, Node, Vec3 } from 'cc';
import { ResourceManager } from '../PlayableFramework/Tools/Manager/ResourceManager';
import { Scene } from './Scene';
const { ccclass, property } = _decorator;

@ccclass('PathConfig')
export class PathConfig extends Component {

    public static instance:PathConfig;

    protected onLoad(): void {
        PathConfig.instance = this;
    }
    
    //#region 路径点相关

    getEntryRoad(roomIndex:number):Node{
        var road = ResourceManager.getPoolNode("PathToRoom"+(roomIndex+1));

        return road;
    }

    getEntryToRoom(roomIndex:number):Vec3[]{
        let result:Vec3[] = [];
        {
            var road = ResourceManager.getPoolNode("PathToRoom"+(roomIndex+1));
            var list = road.children.map(children=>children.worldPosition.clone());
            result.push(list[list.length - 1]);

            var room = Scene.instance.rooms[roomIndex];
            result.push(room.entry.worldPosition.clone());
        }
        return result;
    }

    getRoomEntryToSeat(roomIndex:number,seatIndex:number):Vec3[]{
        //此时算顾客已经就位了吧
        let result:Vec3[] = [];
        {
            var room = Scene.instance.rooms[roomIndex];
            result.push(room.entry.worldPosition.clone());
            var p = room.getSeat(seatIndex).getChildByName("路径点");
            for (let i = 0; i < p.children.length; i++) {
                result.push(p.children[i].worldPosition.clone());
            }
        }
        return result;
    }

    getRoomSeatToExit(roomIndex:number,seatIndex:number):Vec3[]{
        //此时算顾客已经就位了吧
        let result:Vec3[] = [];
        {
            var room = Scene.instance.rooms[roomIndex];

            var p = room.getSeat(seatIndex).getChildByName("路径点");


            result.push(p.children[p.children.length - 1].worldPosition.clone());
            result.push(room.getExit().worldPosition.clone());
        }
        return result;
    }

    getRoomToExit(roomIndex:number):Vec3[]{
        let result:Vec3[] = [];
        {
            var road = ResourceManager.getPoolNode("RoomToExit"+(roomIndex+1));
            var list = road.children.map(children=>children.worldPosition.clone());
            for (let i = 0; i < list.length; i++) {
                result.push(list[i]);
            }
        }
        return result;
    }


    //#endregion
}


